/* 
 * File:   Helper.hpp
 * Author: Faisal
 *
 * Created on April 27, 2012, 8:39 PM
 *
 * Description:
 *		Utility class to conver the boost::any values to base c++ types. Currently it is checking for all data types but only conversion is implemented for
 *		integer types. Need to create "to<DataType>" methods to convert values.
 *
 */

#ifndef HHelper_Common

#define HHelper_Common

#include <boost\any.hpp>

#include "Shared.hpp"

using boost::any_cast;

namespace Supetronix
{
	namespace PersistO
	{
		namespace Common
		{
			class Helper
			{
			public:
				static bool isEmpty(const boost::any& operand)
				{
					return operand.empty();
				}

				static bool isInteger(const boost::any& operand)
				{
					return operand.type() == typeid(int);
				}

				static bool isLong(const boost::any& operand)
				{
					return operand.type() == typeid(long);
				}

				static bool isFloat(const boost::any& operand)
				{
					return operand.type() == typeid(float);
				}

				static bool isDouble(const boost::any& operand)
				{
					return operand.type() == typeid(double);
				}

				static bool isCharPtr(const boost::any& operand)
				{
					try
					{
						any_cast<const char *>(operand);
						return true;
					}
					catch(const boost::bad_any_cast&)
					{
						return false;
					}
				}

				static bool isString(const boost::any& operand)
				{
					return any_cast<std::string>(&operand);
				}

				static int toInteger(const boost::any& operand)
				{
					return any_cast<int>(operand);
				}

			};
		}
	}
}

#endif
